/*
	The Shadow Framework - a complete framework for Real Time Graphics based on OpenGL
    Copyright (C) 2008  Alessandro Martinelli  <alessandro.martinelli@unipv.it>

    This file is part of The Shadow Framework.

    The Shadow Framework is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    The Shadow Framework is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Shadow Framework.  If not, see <http://www.gnu.org/licenses/>.
*/

package objLoader.math;

/**
 * This is a transform for a 2D space
 * @author Alessandro Martinelli
 */
public class Transform2D {

	public float A,B,C,D,E,F;
	public float shear,rot,scaleX,scaleY,posX,posY;

	public Transform2D(float a, float b, float c, float d, float e, float f) {
		super();
		A = a;
		B = b;
		C = c;
		D = d;
		E = e;
		F = f;
	}
	
	public float getXt(float x,float y){
		return A*x+B*y+E;
	}

	public float getYt(float x,float y){
		return A*x+B*y+E;
	}
	
	public static Transform2D getShearXY(float f){
		return new Transform2D(1,0,f,1,0,0);
	}
	
	public static Transform2D getShearYX(float f){
		return new Transform2D(1,f,0,1,0,0);
	}
	
	public static Transform2D getRotation(float alpha){
		float cosa=(float)(Math.cos(alpha));
		float sina=(float)(Math.sin(alpha));
		return new Transform2D(cosa,-sina,sina,cosa,0,0);
	}
	
	public static Transform2D getCompound(float alpha,float sx,float sy,float sh,float x,float y){
		float cosa=(float)(Math.cos(alpha));
		float sina=(float)(Math.sin(alpha));
		return new Transform2D(cosa*sx,(cosa*sh-sina)*sy,sina*sx,(sina*sh+cosa)*sy,0,0);
	}
	
	public static Transform2D getScale(float x,float y){
		return new Transform2D(x,0,0,y,0,0);
	}

	public static Transform2D getTranslate(float x,float y){
		return new Transform2D(1,0,0,1,x,y);
	}

	public Transform2D mult(Transform2D t){
		return new Transform2D(A*t.A+B*t.C,
								A*t.B+B*t.D,
								C*t.A+D*t.C,
								C*t.B+D*t.D,
								(A*t.A+B*t.C)*t.E+(A*t.B+B*t.D)*t.F+E,
								(C*t.A+D*t.C)*t.E+(C*t.B+D*t.D)*t.F+F);
	}
	
	public void update(){
		float cosa=(float)(Math.cos(rot));
		float sina=(float)(Math.sin(rot));
		A=cosa*scaleX;
		B=(cosa*shear-sina)*scaleY;
		C=sina*scaleX;
		D=(sina*shear+cosa)*scaleY;
		E=posX;
		F=posY;
	}

	public float getPosX() {
		return posX;
	}

	public void setPosX(float posX) {
		this.posX = posX;
	}

	public float getPosY() {
		return posY;
	}

	public void setPosY(float posY) {
		this.posY = posY;
	}

	public float getRot() {
		return rot;
	}

	public void setRot(float rot) {
		this.rot = rot;
	}

	public float getScaleX() {
		return scaleX;
	}

	public void setScaleX(float scaleX) {
		this.scaleX = scaleX;
	}

	public float getScaleY() {
		return scaleY;
	}

	public void setScaleY(float scaleY) {
		this.scaleY = scaleY;
	}

	public float getShear() {
		return shear;
	}

	public void setShear(float shear) {
		this.shear = shear;
	}

	public float getA() {
		return A;
	}

	public float getB() {
		return B;
	}

	public float getC() {
		return C;
	}

	public float getD() {
		return D;
	}

	public float getE() {
		return E;
	}

	public float getF() {
		return F;
	}
	
	
}
